package com.boardgame.gwt.service.operate;

import cloud.common.redis.redis.service.IRedisService;
import com.boardgame.common.entity.ResponseInfo;
import com.boardgame.gwt.data.GwtGameBoard;
import com.boardgame.gwt.data.space.GwtSpace;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 命令父类
 */
@Service
@Data
public abstract class SyntaxBaseAction implements Serializable {


    protected GwtGameBoard gwtGameBoard;
    protected SyntaxRequest syntaxRequest;
    /**
     * 行动
     */
    public ResponseInfo action(GwtGameBoard gwtGameBoard, SyntaxRequest syntaxRequest, Matcher matcher){
        this.gwtGameBoard = gwtGameBoard;
        this.syntaxRequest = syntaxRequest;
        return null;
    };

    /**
     * 保存到redis
     * @param iRedisService
     */
    public void saveToRedis(IRedisService iRedisService){
        this.gwtGameBoard.saveToRedis(iRedisService);
    }



    /**
     * 获取行动格子
     * @return
     */
    protected GwtSpace getGwtSplace(int row,int column){
       return this.gwtGameBoard.getGwtSplace(row,column);
    }

    /**
     * 获取行动格子
     * @param matcher
     * @return
     */
    protected GwtSpace getGwtSplace(Matcher matcher){
        return this.getGwtSplace(Integer.parseInt(matcher.group(1)),Integer.parseInt(matcher.group(2)));
    }
    /**
     * 正则
     */
    public abstract Pattern getPattern();

    /**
     * 弹出框html模版
     */
    private String templateHtml;
    /**
     * 模版的控制器
     */
    private String templateControl;
}
